package com.yzt.minemodule.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.yzt.minemodule.adapter.OrderDetailItemAdapter;
import com.yzt.zhuju.base.BaseActivity;
import com.yzt.zhuju.network.AresSubscriber;
import com.yzt.zhuju.network.biz.BizLayer;
import com.yzt.zhuju.network.entity.user.OrderBean;
import com.yzt.zhuju.widget.tuiview.TUITextView;
import com.yzt.zhuju.widget.widget.ImageLoadManger;
import com.yzt.minemodule.R;
import com.yzt.p_base.utils.ToastUtil;
import com.yzt.plugin_widget.RoundImageView;

/**
 * 作者：bobwang
 * 创建时间：2023-11-19 19:17:42
 * 描述：订单详情
 */
public class OrderDetailActivity extends BaseActivity {

    private String orderId;

    public static void startSelf(Context activity, String extraId) {
        activity.startActivity(new Intent(activity, OrderDetailActivity.class)
                .putExtra("extra_id", extraId));
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_order_detail;
    }

    RoundImageView imgCover;
    TextView tv_title;
    TextView tv_time;
    TextView tv_money;
    TUITextView tv_pay;

    @Override
    public void installViews() {
        orderId = getIntent().getStringExtra("extra_id");

        imgCover = findViewById(R.id.img_cover);
        tv_title = findViewById(R.id.tv_title);
        tv_time = findViewById(R.id.tv_time);
        tv_money = findViewById(R.id.tv_money);
        tv_pay = findViewById(R.id.tv_pay);
        tv_pay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.showMessage("去支付");
            }
        });

        initRecycle();

        getPageData();
    }

    private OrderDetailItemAdapter adapter;

    private void initRecycle() {
        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        adapter  =new OrderDetailItemAdapter();
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(adapter);
    }

    /**
     * 获取订单列表
     */
    public void getPageData() {
        BizLayer.getInstance().getMineModule().getOrderDetail(orderId, new AresSubscriber<OrderBean>() {
            @Override
            protected void onSuccess(OrderBean bean) {
                ImageLoadManger.loadIv(mActivity, bean.getCover(), imgCover);
                tv_title.setText(bean.getSubject());
                tv_time.setText(bean.getInfo());
                tv_money.setText(bean.getAmount());
                //  0：待支付，1：已支付，2：已关闭，9：已退款 ]
                if (bean.getStatus() == 0) {
                    mTitleBar.setTitle("待支付");
                    tv_pay.setVisibility(View.VISIBLE);
                } else if (bean.getStatus() == 1) {
                    mTitleBar.setTitle("已支付");
                } else if (bean.getStatus() == 2) {
                    mTitleBar.setTitle("已关闭");
                } else if (bean.getStatus() == 9) {
                    mTitleBar.setTitle("已退款");
                }

                adapter.addData(bean.getItemList());
            }

            @Override
            protected void onFinallyEnd() {
                super.onFinallyEnd();
            }
        });
    }
}
